﻿using Enyim.Caching;
using Enyim.Caching.Memcached;
using OCS.Memcached;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MCDemo
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {

                MemcachedClient mc = new MemcachedClient();


                //MemcachedClient mc = MemCached.getInstance();

                Random rd = new Random();

                var timer = Stopwatch.StartNew();





                ////1.可用性
                //mc.Store(StoreMode.Set, "hello", "lance");
                //MessageBox.Show(timer.ElapsedMilliseconds.ToString() + mc.Get("hello"));




                ////2.循环性能
                for (int i = 0; i < 100000; i++)
                {
                    int j = rd.Next(10000);

                    if (j % 2 == 0)
                        mc.Store(StoreMode.Set, i.ToString(), string.Format("item {0}", j));
                }


                MessageBox.Show(timer.ElapsedMilliseconds.ToString());



                timer = Stopwatch.StartNew();

                ////3.多key读取

                List<string> keys = new List<string>();

                for (int i = 0; i < 100; i++)
                {
                    keys.Add(i.ToString());
                }

                var result = mc.Get(keys.ToArray());





                MessageBox.Show(timer.ElapsedMilliseconds.ToString());



            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }

        private void button2_Click(object sender, EventArgs e)
        {

        }
    }
}
